using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Linq;
using System.Collections.Generic;

namespace QLTV.Reports
{
    public partial class rpt : DevExpress.XtraReports.UI.XtraReport
    {
        public rpt()
        {
            InitializeComponent();
        }

        public void loadData()
        {
            Database.dsReportTableAdapters.tadOnBoarList tadonboardList = new Database.dsReportTableAdapters.tadOnBoarList();
            Database.dsReport.tblOnBoarListDataTable dt = new Database.dsReport.tblOnBoarListDataTable();
            tadonboardList.Fill(dt);
            List<int> listID = (from d in dt.AsEnumerable()
                                orderby d.cGroupName ascending
                                select d.nVesselId).Distinct().ToList<int>();
            bool flag = false;
            Datasource data = null;
            List<Datasource> listData = new List<Datasource>();
            for (int i = 0; i < listID.Count; i++)
            {

                data = new Datasource();
                if (i < listID.Count)
                {
                    data.value1 = listID.ToArray()[i];
                }
                if (i + 1 < listID.Count)
                {
                    data.value2 = listID.ToArray()[i + 1];
                }
                if (i + 2 < listID.Count)
                {
                    data.value3 = listID.ToArray()[i + 2];
                }
                if (i + 3 < listID.Count)
                {
                    data.value4 = listID.ToArray()[i + 3];
                    flag = true;
                }
                if (data != null)
                    listData.Add(data);
                if (flag)
                {
                    i = i + 3;
                    flag = false;
                }
                else
                    break;

            }


            this.DataSource = listData;
        }

        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

            if ((Int32)this.GetCurrentColumnValue("value1") != 0)
                ((rptOnBoard)part1.ReportSource).loadataByVesselID((Int32)this.GetCurrentColumnValue("value1"));
            else
                part1.ReportSource = null;
            if ((Int32)this.GetCurrentColumnValue("value2") != 0)
                ((rptOnBoard)part2.ReportSource).loadataByVesselID((Int32)this.GetCurrentColumnValue("value2"));
            else
                part2.ReportSource = null;
            if ((Int32)this.GetCurrentColumnValue("value3") != 0)
                ((rptOnBoard)part3.ReportSource).loadataByVesselID((Int32)this.GetCurrentColumnValue("value3"));
            else
                part3.ReportSource = null;
            if ((Int32)this.GetCurrentColumnValue("value4") != 0)
                ((rptOnBoard)part4.ReportSource).loadataByVesselID((Int32)this.GetCurrentColumnValue("value4"));
            else
                part4.ReportSource = null;

        }


    }

    public class Datasource
    {
        public int value1 { get; set; }
        public int value2 { get; set; }
        public int value3 { get; set; }
        public int value4 { get; set; }
    }
}
